package org.NooLab.itexx.storage.somfluid.db;

import java.io.Serializable;
import java.util.Comparator;

class xcComparator implements Comparator, Serializable{

	int criterion;
	int direction=0;
	
	/** 1 = smallest first, -1 = largest first*/
	public xcComparator(int dir){
		direction = dir;
		criterion = 1;
	}
	/** criterion : 1=distance, 2=index, 3=secondary index, 4=string */
	public xcComparator(int criterion, int dir){
		direction = dir;
		this.criterion = criterion;
	}
	
	@Override
	public int compare(Object obj1, Object obj2) {
		
		int result = 0;
		XColumn ixd2,ixd1;
		double v1=0,v2=0 ;

		ixd1 = (XColumn)obj1;
		ixd2 = (XColumn)obj2;

		if (criterion<=1){
			v1 = ixd1.pos ;
			v2 = ixd2.pos ;
		}

		if (criterion==2){
			v1 = ixd1.index ;
			v2 = ixd2.index ;
		}
		 
		
		
		if (direction>=0){
			if (v1>v2){
				result = 1;
			}else{
				if (v1<v2){
					result = -1 ;
				}
			}
		}else{
			if (v1>v2){
				result = -1;
			}else{
				if (v1<v2){
					result = 1 ;
				}
			}
			
		}
		
		return result;
	}
	public int getCriterion() {
		return criterion;
	}
	public void setCriterion(int criterion) {
		this.criterion = criterion;
	}
	public int getDirection() {
		return direction;
	}
	public void setDirection(int direction) {
		this.direction = direction;
	}
	
}


